<?php
/**
 * 컨텐츠 관련 model
 * 
 * @author gudals
 * @since 2013-07-19
 */

class modelContContentsInfo extends modelContBase
{
    /**
     * 등록
     * 
     * @param array $aReq 등록정보
     * @return boolean|Ambigous <NULL, multitype:void , void, unknown>
     */
    public function insert($aReq)
    {
        $aReq = addSlashesVariable($aReq, array('contents_desc'));
        
        if (chkTypesVariable(array('int' => $aReq['cate_num'], 'int' => $aReq['user_num'], 'string' => $aReq['contents_desc'])) === false) {
            return false;
        }

        $sQuery = "
            insert into bf_contents (
                cate_num,
                contents_ymd,
                contents_desc,
                contents_img,
                user_num,
                reg_ts
            ) values (
                '".$aReq['cate_num']."',
                '".date('Ymd')."',
                '".$aReq['contents_desc']."',
                '".$aReq['contents_img']."',
                '".$aReq['user_num']."',
                UNIX_TIMESTAMP()
            )
        ";
        
        return $this->executeQuery($sQuery, 'exec');
    }
    
    /**
     * 총 건수
     * 
     * @return Ambigous <NULL, multitype:void , void, unknown>
     */
    public function getTotal($aReq)
    {
        $sWhere = '';
        if (empty($aReq['cate']) === false) {
            $sWhere = " and cate_num = '".$aReq['cate']."'";
        }
        
        $sQuery = "
            select
                count(*) as cnt
            from
                bf_contents
            where
                contents_status = 'Y'
                ".$sWhere."
        ";
        
        return $this->executeQuery($sQuery, 'row');
    }
    
    public function getList($aReq, $iOffset, $iPerPage)
    {
        $sWhere = '';
        if (empty($aReq['cate']) === false) {
            $sWhere = " and cate_num = '".$aReq['cate']."'";
        }
        
        $sQuery = "
            select
                cate_num,
                contents_num,
                contents_ymd,
                contents_desc,
                contents_img,
                user_num,
                comment_cot,
                like_cot,
                reg_ts
            from
                bf_contents
            where
                contents_status = 'Y'
                ".$sWhere."
            order by
                contents_num desc
            limit
                ".$iOffset.", ".$iPerPage."
        ";
        
        return $this->executeQuery($sQuery, 'rows');
    }
}